<template>
  <div>
    <el-dialog title="群发消息" width="50%" :visible.sync="mesFlag">
      <!-- v-bind="$attrs"  实现父传子的数据 直接给组件的属性 -->
      <el-form v-bind="$attrs">
        <el-form-item>
          <div style="border: 1px solid #ccc; padding: 10px;">
            <el-tag
              v-for="tag in userNames"
              :key="tag.id"
              style="margin-right: 10px"
              closable
              :disable-transitions="false"
              @close="handleClose(tag)"
            >
              {{ tag.username }}
            </el-tag>
          </div>
        </el-form-item>
        <el-form-item label="消息类型" label-width="120px">
          <el-select v-model="type">
            <el-option :value="1" label="通知消息" />
            <el-option :value="2" label="提示消息" />
            <el-option :value="3" label="重要消息" />
            <el-option :value="4" label="紧急消息" />
          </el-select>
        </el-form-item>
        <el-form-item
          label="通知内容"
          label-width="120px"
          :rules="[
            { min: 5, message: '最少输入5个字符', trigger: 'blur' },
          ]"
        >
          <el-input v-model="content" type="textarea" />
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button>取消</el-button>
        <el-button type="primary" @click="toSendMes">群发通知</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { sendMessageApi } from '@/api/personnel'
export default {
  props: ['userIds', 'userNames'],
  data() {
    return {
      mesFlag: false, // 弹出层控制
      type: '', // 消息类型
      content: '', // 消息内容
      dynamicTags: ['标签一', '标签二', '标签三']
    }
  },
  mounted() {
    // this.$attrs.liname        this.$attrs 接受父传子 除props之外的数据
    // 多用于完成继承
  },
  methods: {
    async toSendMes() { // 发送消息接口
      const res = await sendMessageApi({
        userIds: this.userIds,
        type: this.type,
        content: this.content
      })
      console.log(res, '发送消息')
      this.$message.success('发送成功')
      this.type = ''
      this.content = ''
      this.$emit('clearIds') // 父组件清空所有内容
      this.mesFlag = false // 关闭弹出层
    },
    handleClose(tag) {
      // 将名字传给父组件
      this.$emit('closeTag', tag)
    }
  }
}
</script>
<style lang="scss">

</style>
